<template>
	<view class="">
		<view class="inputs">
			<text class="xing">商品名称：</text><input type="text" v-model="ProductName" placeholder="请输入产品名称"/>
		</view>
		<view class="inputs">
			<text class="xing">箱条码：</text><input type="text" v-model="OutSKU" placeholder="请输入箱条码"/>
		</view>
		<view class="inputs" style="align-items: inherit;">
			<text class="xing">商品码：</text><input type="text" v-model="SKU" @input="getRefPrice30" placeholder="请输入商品码"/>
		</view>
		<view class="inputs" style="align-items: inherit;">
			<text>订货数量：</text><input class="number" type="number" v-model="OutQty" placeholder="请输入订货数量"/><text>箱/件</text>
		</view>
		<view class="inputs" style="align-items: inherit;">
			<text :class="OutQty!=''&&OutQty!=0?'xing':''">进货价：</text><input type="number" v-model="OutPrice" placeholder="请输入进货价"/>
		</view>
		<view class="inputs" style="align-items: inherit;">
			<text>30天内最低参考价：</text><input type="text" class="disbaled" disabled v-model="RefOutPrice30" placeholder="请输入30天内最低参考价"/>
		</view>
		<view class="inputs" style="align-items: inherit;">
			<text>订货数量：</text><input class="number" type="number" v-model="Qty" placeholder="请输入商品码"/><text>瓶/个</text>
		</view>
		<view class="inputs" style="align-items: inherit;">
			<text :class="Qty!=''&&Qty!=0?'xing':''">进货价：</text><input type="number" v-model="Price" placeholder="请输入进货价格"/>
		</view>
		<view class="inputs" style="align-items: inherit;">
			<text>30天内最低参考价：</text><input class="disbaled" type="number" disabled v-model="RefPrice30" placeholder="请输入天内最低参考价"/>
		</view>
		<view class="inputs" style="align-items: inherit;">
			<text>供货商：</text><input type="text" v-model="SupperName" placeholder="请输入供货商"/>
		</view>
		<view class="inputs" style="align-items: inherit;">
			<text>联系电话：</text><input type="number" v-model="SupperPhone" placeholder="请输入供货商电话"/>
		</view>
		<view class="sumbit" @click="sumbitData">
			提  交
		</view>
		<view class="sumbit" @click="goReport" style="margin-top:20rpx ;">
			我的业绩
		</view>
	</view>
</template>

<script>
	export default{
		data(){
			return {
				"ProductName": "",//商品名称
				 "OutSKU": "", //箱条码
				 "SKU": "", //商品码
				 "OutQty": '',//订货数量 箱  件
				 "OutPrice": '',//进货价
				 "RefOutPrice30": 0.00,//30天内最低参考价
				 "Qty": '',////订货数量瓶 个
				 "Price":'' ,//进货价格
				 "RefPrice30": 0.00,// 30天内最低参考价
				 "SupperName": "",//供货商
				 "SupperPhone": "",//电话
				 "UserId": this.common.getStore('UserId'), //用户id
				 "ShopId": ''  //门店id
			}
		},
		onLoad(options){
			this.ShopId = options.shopId;
		},
		methods:{
			// 根据商品码获取最近30天最低价
			getRefPrice30(e){
				
				if(this.SKU == ''){
					this.RefOutPrice30 = 0.00;
					this.RefPrice30 = 0.00;
					return 
				}
				// RefOutPrice30\RefPrice30
				let data = {
					UserId:this.UserId,
					ShopId:this.ShopId,
					Sku:this.SKU
				}
				console.log(this.SKU );
				this.$api.getShopOrderApi(data).then(res=>{
					console.log(res);
					this.RefOutPrice30 = res.Data.OutPrice;
					this.RefPrice30 = res.Data.Price;
				})
			},
			sumbitData(){
				if(!this.ProductName){
					this.common.toast('none','请填写商品名称!');
					return;
				}
				if(!this.OutSKU){
					this.common.toast('none','请填写箱条码!');
					return;
				}
				if(!this.SKU){
					this.common.toast('none','请填写商品码!');
					return;
				}
				if(this.OutQty!=0&&this.OutQty!=''){
					if(this.OutPrice == ''){
						this.common.toast('none','请填写进货价!');
						return;
					}
				}
				if(this.Qty!=0&&this.Qty!=''){
					if(this.Price == ''){
						this.common.toast('none','请填写进货!');
						return;
					}
				}
				let data = {
					  "ProductName": this.ProductName,
					  "OutSKU": this.OutSKU,
					  "SKU":this.SKU,
					  "OutQty": this.OutQty,
					  "OutPrice":this.OutPrice,
					  "RefOutPrice30":this.RefOutPrice30,
					  "Qty": this.Qty,
					  "Price": this.Price,
					  "RefPrice30":this.RefPrice30,
					  "SupperName": this.SupperName,
					  "SupperPhone": this.SupperPhone,
					  "UserId": this.common.getStore('UserId'),
					  "ShopId": this.ShopId
				}
				
				this.$api.ShopOrderApi(data).then(res=>{
					console.log(res,1111);
					if(res.StatusCode == 200){
						this.common.toast('none','新增成功！');
						this.ProductName=  "",//商品名称
						this.OutSKU= "", //箱条码
						 this.SKU=  "", //商品码
						 this.OutQty=  '',//订货数量 箱  件
						 this.OutPrice=  '',//进货价
						 this.RefOutPrice30=  0,//30天内最低参考价
						 this.Qty=  '',////订货数量瓶 个
						 this.Price= '' ,//进货价格
						 this.RefPrice30=  0,// 30天内最低参考价
						 this.SupperName=  "",//供货商
						 this.SupperPhone= "",//电话
						 this.UserId=  this.common.getStore('UserId'), //用户id
						 this.ShopId =  this.ShopId  //门店id
					}
				})
			},
			goReport(){
				uni.navigateTo({
					url:'/pages/myreport/myReport?shopId='+this.ShopId
				})
			}
		}
	}
</script>

<style>
	.number{
		width: 60%;
	}
	.disbaled{
		background: rgba(0,0,0,.1);
	}
	.sumbit{
		font-size: 32rpx;
	}
	input,input::placeholder{
		font-size: 32rpx !important;
	}
</style>
